(function(){
  var option = null;
  chrome.extension.sendRequest(null, function( response ){
    option = response;
    main(option);
  });
})();

function main(option){
  zen(option);
  zen_textarea.setup({pretty_break: true});
  
  var shortcuts = option["shortcuts"];
  for(var i=0; i<shortcuts.length; i++){
    zen_textarea.shortcut(shortcuts[i].key, shortcuts[i].action);
  }
  var textareas = document.getElementsByTagName('textarea');
  var textareasLength = textareas.length;
  
  for (var i = 0; i < textareasLength; i++) {
    var style = document.defaultView.getComputedStyle(textareas[i], '').display;
    if(style != "none"){
      var img = document.createElement('img');
//    img.src = chrome.extension.getURL('zc-powered.png');
      img.src = 'http://zen-coding.ru/textarea/zc-powered.png';
      img.alt = 'Powered by Zen Coding';
      img.width = '94';
      img.height = '16';
      img.addEventListener('click', function(){zen_textarea.showInfo();}, false);
      img.style.cursor = 'pointer';
      img.style.display = 'block';
      textareas[i].parentNode.insertBefore(img, textareas[i].nextSibling);
    }
  }
}